package com.skcc.cop.mrtaxi.util;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public final class DatabaseUtil {

	public static int getIntValue(Cursor cursor, String key) {
		int indexId = -1;
		indexId = cursor.getColumnIndex(key);
		if (indexId >= 0) {
			return cursor.getInt(cursor.getColumnIndex(key));
		}
		return 0;
	}

	public static String getStringValue(Cursor cursor, String key) {
		int indexId = -1;
		indexId = cursor.getColumnIndex(key);
		if (indexId >= 0) {
			return cursor.getString(cursor.getColumnIndex(key));
		}
		return "";
	}

	public static long getLongValue(Cursor cursor, String key) {
		int indexId = -1;
		indexId = cursor.getColumnIndex(key);
		if (indexId >= 0) {
			return cursor.getLong(cursor.getColumnIndex(key));
		}
		return 0;
	}

	public static double getDoubleValue(Cursor cursor, String key) {
		int indexId = -1;
		indexId = cursor.getColumnIndex(key);
		if (indexId >= 0) {
			return cursor.getDouble(cursor.getColumnIndex(key));
		}
		return 0.0;
	}

	public static boolean insert(SQLiteDatabase database, String tableName, ContentValues conVal) {
		long reLong = database.insert(tableName, null, conVal);
		if (reLong != -1) {
			return true;
		}
		return false;
	}
	
	public static boolean update(SQLiteDatabase database, String tableName, ContentValues conVal, String where, String[] whereClause) {
		int reInt = database.update(tableName, conVal, where, whereClause);
		if (reInt > 0) {
			return true;
		}
		return false;
	}
	
	public static boolean delete(SQLiteDatabase database, String tableName, String where, String[] whereClause) {
		int reInt = database.delete(tableName, where, whereClause);
		if (reInt > 0) {
			return true;
		}
		return false;
	}
}
